import axios from 'axios'
import qs from 'qs'

let baseUrl = 'http://119.27.173.108';

/****************************共用接口****************************/

//传值
export const Login = (url,data) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'post',
      baseURL: baseUrl+url,
      data: qs.stringify(data)
    }).then((res) => {
      resolve(res.data)
    }).catch((err) => {
      reject(err.response)
    })
  })
}

//传值
export const Post = (url,token,data) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'post',
      baseURL: baseUrl+url,
      headers: {Authorization:"Bearer "+token},
      data: qs.stringify(data)
    }).then((res) => {
      resolve(res.data)
    }).catch((err) => {
      reject(err.response)
    })
  })
}

//获取
export const Get = (url,token) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'get',
      baseURL: baseUrl+url,
      headers: {Authorization:"Bearer "+token}
    }).then((res) => {
      resolve(res.data)
    }).catch((err) => {
      reject(err.response)
    })
  })
}

//修改
export const Put = (url,token,data) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'put',
      baseURL: baseUrl+url,
      headers: {Authorization:"Bearer "+token},
      data:data
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err.response)
    })
  })
}

//删除
export const Delete = (url,token) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'delete',
      baseURL: baseUrl+url,
      headers: {Authorization:"Bearer "+token}
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      rreject(err.response)
    })
  })
}

